GBML manual / Maths

roll_reseed

Starts the roll stream again from `seed`. Every run of a ROM rolls the same numbers in the same order unless something calls this, so this is how a project asks for a different game each time.

Syntax

roll_reseed(seed)

Arguments

NameType
seedint

Returns

Nothing.

Description

Starts the roll stream again from seed. Every run of a ROM rolls the same numbers in the same order unless something calls this, so this is the one place a project decides it wants a different game each time.

Any whole number is a legal seed, 0 included.

Example

roll_reseed(20260921);

A fixed seed, chosen by you: every run from here rolls the same sequence, and it is a different sequence from the one the ROM would have rolled on its own. That is how you replay the exact run that produced a bug, or hand a level a number a player can share and compare.

What to seed from for a different game each time

A Game Boy Advance has no clock and no entropy of its own, so the usual answer is the player: count frames from boot, and reseed from that count the moment they first press anything.

// Create
ticks = 0;
seeded = false;

// Step
ticks += 1;

if (!seeded && btn_pressed(BTN_START)) {
    roll_reseed(ticks);
    seeded = true;
}

Nobody presses on exactly the same frame twice, so the stream ends up different on every real play while staying perfectly repeatable in a recording nobody touches. Reseed once and leave it alone - calling this every frame would pin the stream to whatever the seed is doing rather than letting it run.

What a save does not carry

The roll stream is not part of a save file. Loading a save resumes wherever the current run has got to, not wherever the save was made. So never rebuild saved world state out of rolls - save what was decided (which chest held what), not the seed that decided it.

What this does not reseed

Only what a project itself rolls. Particle jitter and camera_shake keep their own separate streams, and this leaves both of them exactly where they were.

That is deliberate rather than an oversight: if they shared the project's stream, adding a single roll_int call anywhere would change every particle and every shake frame in every room of the game.

On the GBA

A Game Boy Advance has no clock to seed from, which is why runs repeat by default. The usual trick on this machine is to reseed from the frame count the first time the player presses anything, so the stream depends on human timing. Any whole number is a legal seed, 0 included. This reseeds only what a project itself rolls - particle jitter and camera shake keep their own separate streams and are unaffected.

See also: roll_introll_realroll_chanceroll_one_oflist_shufflearray_shufflegrid_shuffle